#include <iostream>
#include <list>
#include <stack>
#include <queue>
using namespace std;

void Stack()
{
	stack<char> S;
	char x, y;
	x = 'n'; y = 'g';
	S.push(x); S.push('i'); S.push(y);
	S.pop(); S.push('r'); S.push('t'); S.push(x);
	S.pop(); S.push('s');

	while (!S.empty())//gnirts
	{
		x = S.top();
		S.pop();
		cout << x;
	};

	cout << y;
}


void Queue()
{
	queue<char> Q;
	char x, y;
	x = 'n'; y = 'g';

	Q.push(x); Q.push('i'); Q.push(y);
	Q.pop(); Q.push('r'); Q.push('t'); Q.push(x);
	Q.pop(); Q.push('s');

	while (!Q.empty()) //grtns
	{
		x = Q.front();
		Q.pop();
		cout << x;
	};
	cout << y;
}

int main()
{
	Stack();
	cout << "\n";
	Queue();

	return 0;
}